package com.hktf.uilib.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class PushDBHelper extends SQLiteOpenHelper {

    /**
     * 数据库版本号
     */
    private static final int DB_VERSION = 4; //数据库版本由3升到4
    /**
     * 数据库名称
     */
    private static final String DB_NAME = "Push_db";


    private static final String CREATE_PUSH_TB = "create table push_info_tb ("
            + "_id integer primary key autoincrement,"
            + "msgid integer,"
            + "title varchar,"
            + "caption varchar,"
            + "extreUrl varchar,"
            + "datetime varchar,"
            + "pushtype varchar,"
            + "state varchar,"
            + "flag varchar,"
            + "type integer)";


    public PushDBHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_PUSH_TB);
    }


    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        if (oldVersion < 2) {
            db.execSQL("ALTER TABLE push_info_tb ADD COLUMN pushtype varchar;");
        }
        if (oldVersion < 3){
            db.execSQL("ALTER TABLE push_info_tb ADD COLUMN type integer;");
        }
        if (oldVersion < 4){
            db.execSQL("ALTER TABLE push_info_tb ADD COLUMN flag varchar;");
        }

    }

    @Override
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //super.onDowngrade(db, oldVersion, newVersion);
        db.execSQL("DROP TABLE IF EXISTS push_info_tb;");
        onCreate(db);
    }
}
